What we need: 1. Monitor 2. Raspi 5 and its related components (power wire) 3. Micro Hdmi-VGA wire to connect Raspi with monitor 4. mouse and keyboard 5. Wifi environment
open cmd and type 'sudo raspi-config' then open SSH and VNC function by doing this: Interface options->SSH/VNC->enbale YES and then type 'sudo reboot' in Raspi cmd, restart the system
Firstly, we need to know Raspi' s IP address. Type in 'hostname -I' in command window to check the IP address of Raspi, or login the router' s back-end to check its IP address.Then, install and open VNCRealViewer, create a new connection. With Raspi' s IP address, Raspi and laptop connect to the same Wifi, Raspi' s login username and password, we can use Raspi without monitor.
Jianhua, [2025/6/24 22:13] Now the brightness level can be adjusted in terms of any values between 0-100, which will be calculated as duty cycle for brightness level. Since frequency doesnt make a big impact on it when it is above 100 or 200 hz, frequency is always set as 200hz. Jianhua, [2025/6/24 22:14] brightness level can be input from user firstly, and then when the program is interrupted, user can change the brightness level and during this time LED will be off.import time import gpiod ''' The frequency is set as a steady value. Duty cycle (brightness) changes in terms of any value ranging from 0-1. ''' # PWM configuration FREQUENCY = 200 # Hz PERIOD = 1.0 / FREQUENCY # Set up GPIO chip = gpiod.Chip('gpiochip0') line = chip.get_line(13) line.request(consumer="pwm_example", type=gpiod.LINE_REQ_DIR_OUT, default_val=0) try: while True: try: # Get duty cycle from user (0-100) input_str = input("Please enter brightness level (0-100): ") duty_cycle = float(input_str) / 100.0 if not 0 <= duty_cycle <= 1: print("Error: Please enter a value between 0 and 100") continue print(f"Generating PWM at {FREQUENCY}Hz with {duty_cycle*100:.1f}% duty cycle") try: while True: # PWM logic line.set_value(1) time.sleep(PERIOD * duty_cycle) line.set_value(0) time.sleep(PERIOD * (1 - duty_cycle)) except KeyboardInterrupt: print("\nChanging duty cycle...") line.set_value(0) continue except ValueError: print("Error: Please enter a valid number") except KeyboardInterrupt: print("\nStop") finally: line.set_value(0) line.release()
Three brightness levels in terms of three frequenciesimport time import gpiod # Initial values FREQUENCY = 200 # Default frequency (Hz) BRIGHTNESS = 50 # Default brightness (%) # Set up GPIO chip = gpiod.Chip('gpiochip0') line = chip.get_line(13) line.request(consumer="pwm_example", type=gpiod.LINE_REQ_DIR_OUT, default_val=0) def get_frequency(): while True: try: freq = float(input("Enter frequency (100-1kHz): ")) if 100 <= freq <= 1000: return freq print("Error: Frequency must be between 100-1kHz") except ValueError: print("Error: Please enter a valid number") def get_brightness(): while True: try: bright = float(input("Enter brightness level (0-100%): ")) if 0 <= bright <= 100: return bright print("Error: Brightness must be between 0-100%") except ValueError: print("Error: Please enter a valid number") def pwm_loop(freq, brightness): period = 1.0 / freq duty_cycle = brightness / 100.0 try: while True: if duty_cycle > 0: line.set_value(1) time.sleep(period * duty_cycle) if duty_cycle < 1: line.set_value(0) time.sleep(period * (1 - duty_cycle)) except KeyboardInterrupt: line.set_value(0) # Turn off when paused return # Main program try: FREQUENCY = get_frequency() BRIGHTNESS = get_brightness() print("\System Running") print(f"Frequency: {FREQUENCY}Hz | Brightness: {BRIGHTNESS}%") while True: pwm_loop(FREQUENCY, BRIGHTNESS) try: choice = input("\nSystem Paused\nChange [F]requency or [B]rightness? : ").upper() if choice == 'F': FREQUENCY = get_frequency() elif choice == 'B': BRIGHTNESS = get_brightness() else: print("Invalid choice. Please enter F or B") continue print(f"\nNew Settings. Frequency: {FREQUENCY}Hz | Brightness: {BRIGHTNESS}%") except KeyboardInterrupt: print("\nStop") break except KeyboardInterrupt: print("\nStop") finally: line.set_value(0) line.release()
It is used to test out specific frequency and duty cycle.import gpiod import time #################### ''' It is used to test out specific frequency and duty cycle. ''' #Parameters PWM_PIN = 13 FREQUENCY = 200 # DUTY_CYCLE = 0.2 # #working periods PERIOD = 1.0 / FREQUENCY # entire period ON_TIME = PERIOD * DUTY_CYCLE # ON TIME OFF_TIME = PERIOD - ON_TIME # OFF TIME #initializa GPIO chip = gpiod.Chip('gpiochip4') pwm_line = chip.get_line(PWM_PIN) pwm_line.request(consumer="PWM", type=gpiod.LINE_REQ_DIR_OUT) try: while True: # ON pwm_line.set_value(1) time.sleep(ON_TIME) # OFF pwm_line.set_value(0) time.sleep(OFF_TIME) except KeyboardInterrupt: print("\nStop") finally: # 清理GPIO pwm_line.set_value(0) pwm_line.release() chip.close()